“La visualización es el proceso de hacer visibles los contrastes, ritmos y eventos que los datos expresan, que no podemos percibir cuando vienen en forma de áridas listas de números y categorías.”1
Interpretar / decodificar la información de forma visual
Guiar hacia el hallazago
ggplot2
Una forma de visualizar
¿Qué es {ggplot2}?
Una implementación del sistema Grammar of graphics (Wilkinson, 2005).
Un esquema pensado en capas (datos –> plano (ejes x e y) –> geometrías)
Un paquete de funciones de aplicación intuitiva.
¿Por qué {ggplot2}?
Tiene un marco de referencia (El grammar of graphics)
Flexible, con especificaciones a nivel de capas.
Sistema de themes, que permiten pulir la apariencia del gráfico
Decenas de extensiones para ampliar la potencia del paquete
Comunidad activa y con mucha predisposición a ayudar.
¿A dónde vamos?
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.2 ✔ tibble 3.3.0
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Rows: 19672 Columns: 13
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (8): region, ruta_natural, provincia_codigo, provincia_nombre, departame...
dbl (5): indice_tiempo, establecimientos, unidades, habitaciones, plazas
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 19672 Columns: 13
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (8): region, ruta_natural, provincia_codigo, provincia_nombre, departame...
dbl (5): indice_tiempo, establecimientos, unidades, habitaciones, plazas
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Gráfico en clave de capas
Así queda nuestra tabla:
df_habitaciones_2022
# A tibble: 3 × 2
tipo habitaciones_n
<chr> <dbl>
1 Hoteleros 185351
2 Otros colectivos 2810
3 Parahoteleros 58490
Gráfico en clave de capas
ggplot(data = df_habitaciones_2022,aes(x = tipo, y = habitaciones_n))
Gráfico en clave de capas
ggplot(data = df_habitaciones_2022,aes(x = tipo, y = habitaciones_n)) +geom_col()
Chapa y pintura
Chapa y pintura - Relleno
ggplot(data = df_habitaciones_2022,aes(x = tipo, y = habitaciones_n)) +geom_col(fill ="red")
ggplot(data = df_habitaciones_2022,aes(x = tipo, y = habitaciones_n)) +geom_col(aes(fill = tipo),color ="black") +labs(title ="Cantidad de habitaciones por tipo de alojamiento")
Chapa y pintura - Referencias
ggplot(data = df_habitaciones_2022,aes(x = tipo, y = habitaciones_n)) +geom_col(aes(fill = tipo),color ="black") +labs(title ="Cantidad de habitaciones por tipo de alojamiento",subtitle ="Argentina, año 2022",x ="",y ="Cant. de habitaciones",caption ="Fuente: Elaboración propia en base al PUNA-MINTURyDEP")
Chapa y pintura - theme
ggplot(data = df_habitaciones_2022,aes(x = tipo, y = habitaciones_n)) +geom_col(aes(fill = tipo),color ="black") +labs(title ="Cantidad de habitaciones por tipo de alojamiento",subtitle ="Argentina, año 2022",x ="",y ="Cant. de habitaciones",caption ="Fuente: Elaboración propia en base al PUNA-MINTURyDEP") +theme_minimal()
Chapa y pintura - theme
ggplot(data = df_habitaciones_2022,aes(x = tipo, y = habitaciones_n)) +geom_col(aes(fill = tipo),color ="black") +labs(title ="Cantidad de habitaciones por tipo de alojamiento",subtitle ="Argentina, año 2022",x ="",y ="Cant. de habitaciones",caption ="Fuente: Elaboración propia en base al PUNA-MINTURyDEP") +theme_minimal() +theme(legend.position ="none")